package cn.trigram.mgb.mixed_simple_dynamic;

import cn.trigram.mgb.ext.AbstractTableGenerateCustomize.DefaultTableGenerateCustomize;
import org.apache.commons.lang3.StringUtils;
import org.mybatis.generator.config.JavaClientGeneratorConfiguration;
import org.mybatis.generator.internal.util.JavaBeansUtil;

public class MixedMybatis3SimpleDefaultTableGenerateCustomize extends DefaultTableGenerateCustomize {

  @Override
  public void configProperty() {

    super.configProperty();

    JavaClientGeneratorConfiguration clientGeneratorConfiguration = context.getJavaClientGeneratorConfiguration();
    String parentPackage =
        clientGeneratorConfiguration.getTargetPackage() + ".dynamic.";
    final String entityClassName = JavaBeansUtil.getCamelCaseString(StringUtils.removeEndIgnoreCase(
        StringUtils.removeStartIgnoreCase(tableConfiguration.getTableName(), this.getTablePrefix()),
        this.getTableSuffix()
    ), true);
    String rootInterface = entityClassName + "DynamicSql";
    /*生成两个Mapper，其中一个是dynamic的，另一个继承dynamic生成的mapper接口*/
    tableConfiguration.addProperty("rootInterface", parentPackage + rootInterface);

  }

}
